﻿
using BUS.BUSService;
using DTO.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace API_AUTHORIZATION.Controls.Authorization.User
{
    /// <summary>
    /// Interaction logic for MyUserInsertControl.xaml
    /// </summary>
    public partial class MyUserInsertControl : UserControl
    {
        public MyUserInsertControl()
        {
            InitializeComponent();
            UserTypeDTO user = new UserTypeDTO();
            user.Id = "asdfasdfads";
            user.UserTypeDes = "asdfadsfasdf";
            user.UserTypeName = "adsfadsfads";
            tableData.ItemsSource = new List<UserTypeDTO>() {user,user,user};
        }

        #region private function
        private void SetNewState()
        {
            txtUserTypeDes.ReFreshAll();
            txtUserTypeName.ReFreshAll();
        }

        private bool SubmitButtonHandle()
        {
            if (txtUserTypeName.IsValid && txtUserTypeDes.IsValid)
            {
                AuthorizationBUSService.InsertUseRTypeDTO(
                    AuthorizationBUSService.GetObjectUserTypeDTO(txtUserTypeName.TextContent,
                    txtUserTypeDes.TextContent));
                return true;
            }
            return false;
        }
        #endregion

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            SetNewState();
        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (SubmitButtonHandle())
            {
                SetNewState();
            }
        }
    }
}
